﻿Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls


<DefaultProperty("Text"), ToolboxData("<{0}:ReadOnlyDropDownList runat=server></{0}:ReadOnlyDropDownList>")> _
Public Class ReadOnlyDropDownList
    Inherits DropDownList

    Public _ReadOnlyWidth As Integer = 0

    <Category("Behavior"), DefaultValue(0), Localizable(True)> _
    Property ReadOnlyWidth() As Integer
        Get
            Return _ReadOnlyWidth
        End Get
        Set(ByVal value As Integer)
            _ReadOnlyWidth = value
        End Set
    End Property

    Public _ReadOnlyStyle As Integer = False

    <Category("Behavior"), DefaultValue(False), Localizable(True)> _
    Property ReadOnlyStyle() As Boolean
        Get
            Return _ReadOnlyStyle
        End Get
        Set(ByVal value As Boolean)
            _ReadOnlyStyle = value
        End Set
    End Property

    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
        If Not ReadOnlyStyle Then
            MyBase.Render(writer)
        Else
            Dim textlength As Integer = Me.SelectedItem.Text.Length
            writer.AddAttribute("value", Me.SelectedItem.Text)
            writer.AddAttribute("type", "text")
            writer.AddAttribute("readonly", "readonly")
            writer.AddAttribute("id", Me.ID)
            'writer.AddAttribute("style", "width:" + Convert.ToString(Me.Width.Value + ReadOnlyWidth) + "px;" + "border:solid 0px;" + "text-align:left;")
            writer.RenderBeginTag("input")
            writer.RenderEndTag()
        End If
    End Sub


End Class
